const db=require('../db/index')

// 添加企业
exports.addCompany=(req,res)=>{
    const c=req.body
    console.log("c",c); 
    // if(!sql1){
        const sql=`insert into company(companyName,companyType,registeredCapital,
            establishmentDate,legalRepresentative,companyAddress,companyPhone,companyEmail,
            companyProfile) values(?,?,?,?,?,?,?,?,?)`
        db.query(sql,[c.companyName,c.companyType,c.registeredCapital,c.establishmentDate,c.legalRepresentative,c.companyAddress,
            c.companyPhone,c.companyEmail,c.companyProfile],(err,results)=>{
            console.log("c222",c);  
            console.log("err",err); 
            if(err) return res.cc(err)
            if(results.affectedRows!==1) return res.cc('新增失败')
            res.cc('OK',0)
        })  
    // }
  }

// 获取企业信息
exports.allCompany=(req,res)=>{
    const sql=`select * from company`
    db.query(sql,(err,results)=>{
        if(err) return res.cc(err)
        res.send({
            status:0,
            message:'获取企业',
            companyinfo:results
        })
    })
}

// 更新企业
exports.updateCompany=(req,res)=>{
    const c=req.body    
    console.log("c",c);
    const sql=`update company set companyName=?,companyType=?,registeredCapital=?,
    establishmentDate=?,legalRepresentative=?,companyAddress=?,companyPhone=?,companyEmail=?,
    companyProfile=? where companyId=?`
    db.query(sql,[c.companyName,c.companyType,c.registeredCapital,c.establishmentDate,c.legalRepresentative,c.companyAddress,
        c.companyPhone,c.companyEmail,c.companyProfile,c.companyId],(err,results)=>{
        if(err) return  res.cc(err)
        if(results.affectedRows!==1) return res.cc('更新失败')
        res.send({
            status:0,
            message:'更新成功'
        })
    })
}
  